package com.yuexunit.operationman.nbsy.module.OperationInventory.presenter.impl;

import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationInventory.bean.TempletBean;
import com.yuexunit.operationman.nbsy.module.OperationInventory.model.ITempletModel;
import com.yuexunit.operationman.nbsy.module.OperationInventory.presenter.ITempletPresenter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.ui.view.ITempletView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/9/4.
 */
public class TempletPresenter implements ITempletPresenter{
    private ITempletModel mModel;
    private ITempletView mView;

    public TempletPresenter(ITempletView view, ITempletModel model){
        mModel=model;
        mView=view;
    }


    @Override
    public void getTempletDate(Map<String, String> praise) {
        mModel.getTempletDate(praise)
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
//                        log.info("UserPresenter_doInLogin_SHOW_DIALOG");
                        mView.loadingDialogStatus(AppConfig.SHOW_DIALOG);
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<TempletBean>() {
                    @Override
                    public void onCompleted() {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onNext(TempletBean templetBean) {
                        mView.getTempletDate(templetBean);
                    }
                });
    }
}
